(function(){
    App.models.BaseModel = Backbone.Model.extend({
        defaults: {},
        baseUrl: '',
        doIt: function(url){
            var _self = this;
            $.ajax({
                type: 'POST',
                url: url,
                data: _self.toJSON(),
            }).done(function(result){
                _self.postRequest(result);
            });
        },
        create: function(){
            var _self = this;
            _self.doIt(_self.baseUrl + '/create');
        },
        update: function(){
            var _self = this;
            _self.doIt(_self.baseUrl + '/update');
        },
        delete: function(){
            var _self = this;
            _self.doIt(_self.baseUrl + '/delete');
        },
        postRequest: function(result){
            if(result.code != 1){
                $.gritter.add({
                    class_name: 'gritter-error',
                    text: result.msg,
                });
            }else{
                $.gritter.add({
                    class_name: 'gritter-success',
                    text: result.msg,
                });
                this.trigger('requestSuccess');
            }
        }
    });

})();